#!/bin/bash

# sed -i "s#quay.io#192.168.56.102:5000#g" *
# sed -i "s#k8s.gcr.io#192.168.56.102:5000#g" *
# quay.io ==> quay-mirror.qiniu.com
# gcr.io  ==> registry.aliyuncs.com

QUAY_IO_REPO_ADDR="quay-mirror.qiniu.com"
K8S_GCR_IO_REPO_ADDR="registry.aliyuncs.com"
PRIVATE_ADDR="192.168.56.102:5000"

: > reply_images.list

for image in `cat quay.io.images.list`
do
    echo "$image start ..."
    reply_image=`echo $image | sed "s#quay.io#${QUAY_IO_REPO_ADDR}#g"`
    docker pull ${reply_image}
    private_image=`echo $reply_image | sed "s#$QUAY_IO_REPO_ADDR#${PRIVATE_ADDR}#g"`
    docker tag ${reply_image} ${private_image}
    docker push $private_image
    # docker tag $image $reply_image
    # docker push $reply_image
    echo ""
done

for image in `cat k8s.gcr.io.images.list`
do
    echo "$image start ..."
    reply_image=`echo $image | sed "s#k8s.gcr.io#${K8S_GCR_IO_REPO_ADDR}#g"`
    docker pull ${reply_image}
    private_image=`echo $reply_image | sed "s#$K8S_GCR_IO_REPO_ADDR#${PRIVATE_ADDR}#g"`
    docker tag ${reply_image} ${private_image}
    docker push $private_image
    # docker tag $image $reply_image
    # docker push $reply_image
    echo ""
done

